﻿#include "itemsmanage.h"

ParaItem makeAParaItem(
                       int64_t mcenSel,
                       int paraType,
                       int paraTypeSort,
                       int indexInPara,
                       int bitInWord,
                       int readonly,
                       int valueType,
                       QString paraName,
                       int64_t value,
                       int64_t minval,
                       int64_t maxval,
                       int64_t defvalue,
                       int afterpoint,
                       QString unitstr,
                       QString valuestr,
                       QString selList,
                       int selIdx,
                       int defIdx,
                       int showPriority,
                       int authority)
{
    ParaItem item;

    item.clean();

    item.mcenSel        = mcenSel;      /* 机型选择 */
    item.paraType       = paraType;     /* 参数类型(机器参数、工作参数、花样设置参数...) */
    item.paraTypeSort   = paraTypeSort; /* 参数类型分类(机器参数的速度参数、机器参数的动作参数...) */

    item.indexInPara    = indexInPara;  /* 参数索引，-1，提示型显示; >= 0，该条目在参数中的位置*/
    item.bitInWord      = bitInWord;    /* 参数位索引 */
    item.readonly       = readonly;     /* 只读标志 */
    item.valueType      = valueType;    /* 参数值类型 = 0, 无值; = 1, 数字输入型; = 2, 开关选择型; = 3, 列表选择型 */

    item.paraName       = paraName;     /* 参数名称 */

    item.value          = value;        /* int输入型或选择型参数值 */
    item.minVal         = minval;       /* int输入型参数值范围下限 */
    item.maxVal         = maxval;       /* int输入型参数值范围上限 */
    item.defValue       = defvalue;     /* int输入型或选择型默认参数值 */
    item.afterPoint     = afterpoint;   /* int输入型保留小数位数 */
    item.unitStr        = unitstr;      /* int输入型单位字符串 */
    item.valueStr       = valuestr;     /* 字符输入型参数字符串 */

    item.selList        = selList;      /* 列表选择型的参数列表, 通过"\n"来分割 */
    item.selIdx         = selIdx;       /* 当前选择项索引 */
    item.defIdx         = defIdx;       /* 默认选择项索引 */
    item.showPriority   = showPriority; /* 显示优先级 */
    item.authority      = authority;    /* 显示优先级 */

    return item;
}

bool comparePriority(const ParaItem &item1, const ParaItem &item2)
{
    int pr1, pr2;
    pr1 = item1.showPriority;
    pr2 = item2.showPriority;
    if (pr1 < 0)
    {
        pr1 = 0;
    }
    if (pr2 < 0)
    {
        pr2 = 0;
    }

    return (pr1 < pr2);
}

//各个机型通用参数-软件设置参数
void initSoftwareParasList(QList <ParaItem> & parasList)
{
    //软件设置参数---------------------------
    //软件设置参数-主题；单位：无 ，范围1-3，默认1
    /*parasList.append(makeAParaItem(0,
                                   PARA_TYPE_SOFTWARESET,
                                   0 ,
                                   SET_THEME, 0, 0, PARA_VALUE_TYPE_LIST,//原本是只读设置
                                   QCoreApplication::translate("GLOBAL", "Theme"),//主题
                                   1, 1, 3, 1, 0, "", "",
                                   QCoreApplication::translate("GLOBAL", "Theme1:1;Theme2:2;Theme3:3"),//主题1:1;主题2:2;主题3:3
                                   0, 0, 0x0001, operate));
    */

    //软件设置参数-语言；单位：无 ，范围0-1，默认0
    parasList.append(makeAParaItem(0,
                                   PARA_TYPE_SOFTWARESET,
                                   0 ,
                                   SET_LANGUAGE, 0, 0, PARA_VALUE_TYPE_LIST,
                                   QCoreApplication::translate("GLOBAL", "Language"),//语言
                                   0, 0, 5, 0, 0, "", "",
//                                   QCoreApplication::translate("GLOBAL", "Chinese:0;English:1;Vietnamese:6"),
                                   QCoreApplication::translate("GLOBAL", "Chinese:0;English:1"),
                                   0, 0, 0x0002, operate));

//    #ifdef Q_OS_WIN
    //软件设置参数-字体大小
    parasList.append(makeAParaItem(0,
                                   PARA_TYPE_SOFTWARESET,
                                   0 ,
                                   SET_FONTSIZE, 0, 0, PARA_VALUE_TYPE_INT,
                                   QCoreApplication::translate("GLOBAL", "Fontsize"),//字体大小
                                   0, 4, 32, 0, 0, "", "",
                                   (""),
                                   0, 0, 0x0002, operate));
//    #endif

    //软件设置参数---------------------------
}

//各个机型通用参数-时间设置参数
void initTimeParasList(QList <ParaItem> & parasList)
{
    //时间设置参数---------------------------
    //时间设置参数-年；单位：无 ，范围1000-9999，默认1000
    parasList.append(makeAParaItem(0,
                                   PARA_TYPE_TIMESET,
                                   0 ,
                                   1, 0, 0, PARA_VALUE_TYPE_INT,
                                   QCoreApplication::translate("GLOBAL", "Year"),//年
                                   1000, 1000, 9999, 1000, 0, "", "",
                                   "", 0, 0, 0x0000, operate));

    //时间设置参数-月；单位：无 ，范围1-12，默认1
    parasList.append(makeAParaItem(0,
                                   PARA_TYPE_TIMESET,
                                   0 ,
                                   2, 0, 0, PARA_VALUE_TYPE_INT,
                                   QCoreApplication::translate("GLOBAL", "Month"),//月
                                   1, 1, 12, 1, 0, "", "",
                                   "", 0, 0, 0x0001, operate));

    //时间设置参数-日；单位：无 ，范围1-31，默认1
    parasList.append(makeAParaItem(0,
                                   PARA_TYPE_TIMESET,
                                   0 ,
                                   3, 0, 0, PARA_VALUE_TYPE_INT,
                                   QCoreApplication::translate("GLOBAL", "Day"),//日
                                   1, 1, 31, 1, 0, "", "",
                                   "", 0, 0, 0x0002, operate));

    //时间设置参数-时；单位：无 ，范围0-23，默认0
    parasList.append(makeAParaItem(0,
                                   PARA_TYPE_TIMESET,
                                   0 ,
                                   4, 0, 0, PARA_VALUE_TYPE_INT,
                                   QCoreApplication::translate("GLOBAL", "Hour"),//时
                                   0, 0, 23, 0, 0, "", "",
                                   "", 0, 0, 0x0003, operate));

    //时间设置参数-分；单位：无 ，范围0-59，默认0
    parasList.append(makeAParaItem(0,
                                   PARA_TYPE_TIMESET,
                                   0 ,
                                   5, 0, 0, PARA_VALUE_TYPE_INT,
                                   QCoreApplication::translate("GLOBAL", "Minute"),//分
                                   0, 0, 59, 0, 0, "", "",
                                   "", 0, 0, 0x0004, operate));

    //时间设置参数-秒；单位：无 ，范围0-59，默认0
    parasList.append(makeAParaItem(0,
                                   PARA_TYPE_TIMESET,
                                   0 ,
                                   6, 0, 0, PARA_VALUE_TYPE_INT,
                                   QCoreApplication::translate("GLOBAL", "Second"),//秒
                                   0, 0, 59, 0, 0, "", "",
                                   "", 0, 0, 0x0005, operate));
    //时间设置参数---------------------------
}

//各个机型通用参数-网络管理参数
void initNetworkParasList(QList <ParaItem> & parasList)
{

    //网络管理参数-服务器IP设置；单位：无 ，范围无，默认192.168.16.253
    parasList.append(makeAParaItem(0,
                                   PARA_TYPE_NETWORKSET,
                                   0 ,
                                   SET_MACHINE_SERVERIP, 0, 0, PARA_VALUE_TYPE_STRINPUT,
                                   QCoreApplication::translate("GLOBAL", "Server IP settings"),//服务器IP设置
                                   0, 0, 0, 0, 0, "", "192.168.16.253",
                                   "",
                                   0, 0, 0x0007, operate));

    //网络管理参数-服务器端口设置；单位：无 ，范围0-65535，默认5000
    parasList.append(makeAParaItem(0,
                                   PARA_TYPE_NETWORKSET,
                                   0 ,
                                   SET_MACHINE_SERVERPORT, 0, 0, PARA_VALUE_TYPE_INT,
                                   QCoreApplication::translate("GLOBAL", "Server port settings"),//服务器端口设置
                                   5000, 0, U16_MAX, 5000, 0, "", "",
                                   "", 0, 0,0x0008, operate));

    //网络管理参数-本地IP设置；单位：无 ，范围无，默认192.168.16.41
    parasList.append(makeAParaItem(0,
                                   PARA_TYPE_NETWORKSET,
                                   0 ,
                                   SET_LOCALIP, 0, 0, PARA_VALUE_TYPE_STRINPUT,
                                   QCoreApplication::translate("GLOBAL", "Local IP settings"),//本地IP设置
                                   0, 0, 0, 0, 0, "", "192.168.16.41",
                                   "",
                                   0, 0, 0x0009, operate));

    //网络管理参数-本地端口设置；单位：无 ，范围0-65535，默认5001
    parasList.append(makeAParaItem(0,
                                   PARA_TYPE_NETWORKSET,
                                   0 ,
                                   SET_LOCALPORT, 0, 0, PARA_VALUE_TYPE_INT,
                                   QCoreApplication::translate("GLOBAL", "Local port settings"),//本地端口设置
                                   5001, 0, U16_MAX, 5001, 0, "", "",
                                   "", 0, 0,0x000A, operate));
    //网络管理参数---------------------------
}

OutCtrlItem makeAOutCtrlItem(int macType, int showPriority, QString name, int def,
                             QString btn1Str, bool btn1Visible, int btn1ClickFun, int btn1PreFun, int btn1RelFun,
                             QString btn2Str, bool btn2Visible, int btn2ClickFun, int btn2PreFun, int btn2RelFun,
                             QString btn3Str, bool btn3Visible, int btn3ClickFun, int btn3PreFun, int btn3RelFun,
                             QString btn4Str, bool btn4Visible, int btn4ClickFun, int btn4PreFun, int btn4RelFun,
                             QString btn5Str, bool btn5Visible, int btn5ClickFun, int btn5PreFun, int btn5RelFun)
{
    OutCtrlItem item;
    item.clean();

    item.m_macType = macType;
    item.m_showPriority = showPriority;
    item.m_name = name;
    item.m_def  = def;

    item.m_btn1Str = btn1Str;
    item.m_btn1Visible = btn1Visible;
    item.m_btn1ClickFun = btn1ClickFun;
    item.m_btn1PreFun = btn1PreFun;
    item.m_btn1RelFun = btn1RelFun;

    item.m_btn2Str = btn2Str;
    item.m_btn2Visible = btn2Visible;
    item.m_btn2ClickFun = btn2ClickFun;
    item.m_btn2PreFun = btn2PreFun;
    item.m_btn2RelFun = btn2RelFun;

    item.m_btn3Str = btn3Str;
    item.m_btn3Visible = btn3Visible;
    item.m_btn3ClickFun = btn3ClickFun;
    item.m_btn3PreFun = btn3PreFun;
    item.m_btn3RelFun = btn3RelFun;

    item.m_btn4Str = btn4Str;
    item.m_btn4Visible = btn4Visible;
    item.m_btn4ClickFun = btn4ClickFun;
    item.m_btn4PreFun = btn4PreFun;
    item.m_btn4RelFun = btn4RelFun;

    item.m_btn5Str = btn5Str;
    item.m_btn5Visible = btn5Visible;
    item.m_btn5ClickFun = btn5ClickFun;
    item.m_btn5PreFun = btn5PreFun;
    item.m_btn5RelFun = btn5RelFun;

    return item;
}

ShortCutItem makeAShortCutItem(int macType, int showPriority, QString name, QString topImageName, int enumFunction)
{
    ShortCutItem item;
    item.clean();

    item.m_macType = macType;
    item.m_showPriority = showPriority;
    item.m_name = name;
    item.m_topImageName = topImageName;
    item.m_enumFunction = enumFunction;

    return item;
}

//添加辅助功能item
AssistItem makeAAssistItem(int macType, int showPriority, QString name, QString topImageName, int enumFunction)
{
    AssistItem item;
    item.clean();

    item.m_macType = macType;
    item.m_showPriority = showPriority;
    item.m_name = name;
    item.m_topImageName = topImageName;
    item.m_enumFunction = enumFunction;

    return item;
}

PatternSetItem makeAPatternSetItem(int macType, int showPriority, QString name, QString topImageName, int enumFunction)
{
    PatternSetItem item;
    item.clean();

    item.m_macType = macType;
    item.m_showPriority = showPriority;
    item.m_name = name;
    item.m_topImageName = topImageName;
    item.m_enumFunction = enumFunction;

    return item;
}

void initRootHMIConfigurationList(QList<ParaItem> &parasList)
{
    //超级用户界面配置参数-分辨率；单位：无
    parasList.append(makeAParaItem(0,
                                       PARA_TYPE_HMICONFIGURATION,
                                       0 ,
                                       ROOT_RESOLUTION, 0, 0, PARA_VALUE_TYPE_LIST,
                                       QCoreApplication::translate("GLOBAL", "Resolution"),//分辨率
                                       0, 0, 2, 0, 0, "", "",
                                       "1920x1080:0;1024x600:1;800x480:2;",
                                       0, 0, 0x0001, root));

    //软件设置参数-通讯方式；单位：无 ，范围0-2，默认0
    parasList.append(makeAParaItem(0,
                                   PARA_TYPE_HMICONFIGURATION,
                                   0 ,
                                   SET_CONNECTMODE, 0, 0, PARA_VALUE_TYPE_LIST,
                                   QCoreApplication::translate("GLOBAL", "Communication method"),//通讯方式
                                   0, 0, 1, 0, 0, "", "",
                                   QCoreApplication::translate("GLOBAL", "Network:0;SerialPort:1"),//网口:0;串口:1
                                   0, 0, 0x0011, operate));

    //机器类型
    parasList.append(makeAParaItem(0,
                                   PARA_TYPE_HMICONFIGURATION,
                                   0 ,
                                   ROOT_MACTYPE, 0, 0, PARA_VALUE_TYPE_LIST,
                                   QCoreApplication::translate("GLOBAL", "Machine type"),//机器类型
                                   //值，最小值，最大值，默认值
                                   MACHINE_HIGHSPEEDSINGLEQUI, MACHINE_HIGHSPEEDSINGLEQUI, MACHINE_DRAWING, MACHINE_HIGHSPEEDSINGLEQUI, 0, "", "",
                                   QString(QCoreApplication::translate("GLOBAL",
                                                                       "001 McHighSingleQui:0;"
                                                                       "002 FiveHeadPrecisionSewing:1;"
                                                                       "003 ClothingMac:2;"
                                                                       "004 Multineedlerotary:3;"
                                                                       "005 FlatcuttingMac:4;"
                                                                       "006 ThickWiringMac:5;"
                                                                       "007 FlyFlatcutting:6;"
                                                                       "008 Drawing:7;")),
                                   //001 高速单针机:0;002 五头精密缝:1;003 服装机:2;004 多针旋梭:3;005 平板切割机:4;006 粗布布线机:5;007 飞行切割平板切割机:6;008 画线机:7

                                   0, 0, 0x0012, operate));

    //超级用户界面配置参数-产品类型；单位：无
    parasList.append(makeAParaItem(0,
                                       PARA_TYPE_HMICONFIGURATION,
                                       0 ,
                                       ROOT_PRODUCTTYPE, 0, 0, PARA_VALUE_TYPE_LIST,
                                       QCoreApplication::translate("GLOBAL", "Product type"),//产品类型
                                   PRODUCT_NULL, PRODUCT_NULL, PRODUCT_NULL, PRODUCT_NULL, 0, "", "",
                                    QCoreApplication::translate("GLOBAL","ProductNull:")+QString::number(PRODUCT_NULL),//无
                                   0, 0, 0x0013, root));

    //超级用户界面配置参数-是否有自动换梭功能；单位：无
    parasList.append(makeAParaItem(0,
                                       PARA_TYPE_HMICONFIGURATION,
                                       0 ,
                                       ROOT_SHUTTLECHANGE, 0, 0, PARA_VALUE_TYPE_LIST,
                                       QCoreApplication::translate("GLOBAL", "Whether there is a Automatic shuttle change function"),//是否有自动换梭功能
                                       1, 0, 1, 1, 0, "", "",
                                       "No:0;Yes:1",
                                       1, 1, 0x0016, root));

    //超级用户界面配置参数-主背景是否带水印；单位：无
    parasList.append(makeAParaItem(0,
                                       PARA_TYPE_HMICONFIGURATION,
                                       0 ,
                                       ROOT_WATERMARKSET, 0, 0, PARA_VALUE_TYPE_LIST,
                                       QCoreApplication::translate("GLOBAL", "Is there a Richpeace logo"),//是否有富怡标志
                                       1, 0, 1, 1, 0, "", "",
                                       "No:0;Yes:1",
                                       1, 1, 0x0017, root));

    //超级用户界面配置参数-参数是否分类显示；单位：无
    parasList.append(makeAParaItem(0,
                                       PARA_TYPE_HMICONFIGURATION,
                                       0 ,
                                       ROOT_PARASORTSET, 0, 0, PARA_VALUE_TYPE_LIST,
                                       QCoreApplication::translate("GLOBAL", "Parameter is classified"),//参数是否分类显示
                                       0, 0, 1, 0, 0, "", "",
                                       "No:0;Yes:1",
                                       0, 0, 0x0018, root));

    //是否WIFI
    parasList.append(makeAParaItem(0,
                                       PARA_TYPE_HMICONFIGURATION,
                                       0 ,
                                       ROOT_WIFI, 0, 0, PARA_VALUE_TYPE_SW,
                                       QCoreApplication::translate("GLOBAL", "WIFI"),//WIFI
                                       0, 0, 1, 0, 0, "", "",
                                       "",
                                       0, 0, 0x0018, root));

}

//物联网配置参数
void initRootIOTConfigurationList(QList<ParaItem> &parasList)
{
    //超级用户物联网配置-网关连接方式；单位：无
    parasList.append(makeAParaItem(0,
                                   PARA_TYPE_IOTCONFIGURATION,
                                   0 ,
                                   ROOT_GATEWAYCONNECTIONMETHOD, 0, 0, PARA_VALUE_TYPE_LIST,
                                   QCoreApplication::translate("GLOBAL", "Gateway connection method"),//网关连接方式
                                   0, 0, 2, 0, 0, "", "",
                                   QCoreApplication::translate("GLOBAL","Serial port:0; Network port:1"),
                                   0, 0, 0x0011, root));

    //超级用户物联网配置-机架号输入; 单位:无
    parasList.append(makeAParaItem(0,
                                   PARA_TYPE_IOTCONFIGURATION,
                                   0 ,
                                   ROOT_RACKNUMBERINPUT, 0, 0, PARA_VALUE_TYPE_INT,
                                   QCoreApplication::translate("GLOBAL", "Input rack number"),//机架号输入
                                   111189, 0, INT_MAX, 111189, 0, "", "",
                                   "",
                                   0, 0, 0x0012, root));

    //超级用户物联网配置-网络设置; 单位:无
    parasList.append(makeAParaItem(0,
                                   PARA_TYPE_IOTCONFIGURATION,
                                   0 ,
                                   ROOT_NETWORKSETTINGS, 0, 0, PARA_VALUE_TYPE_CLICK,
                                   QCoreApplication::translate("GLOBAL", "Network settings"),//网络设置
                                   0, 0, 0, 0, 0, "", "",
                                   "",
                                   0, 0, 0x0013, root));

    //超级用户物联网配置-工厂预计交货时间; 单位:无
    parasList.append(makeAParaItem(0,
                                   PARA_TYPE_IOTCONFIGURATION,
                                   0 ,
                                   ROOT_DELIVERYTIME, 0, 0, PARA_VALUE_TYPE_STRINPUT,
                                   QCoreApplication::translate("GLOBAL", "Factory expects delivery time"),//工厂预计交货时间
                                   0, 0, 0, 0, 0, "", "",
                                   "",
                                   0, 0, 0x0014, root));

    //超级用户物联网配置-调试进度; 单位:无
    parasList.append(makeAParaItem(0,
                                   PARA_TYPE_IOTCONFIGURATION,
                                   0 ,
                                   ROOT_DEBUGPROGRESS, 0, 0, PARA_VALUE_TYPE_INT,
                                   QCoreApplication::translate("GLOBAL", "Debugging progress"),//调试进度
                                   0, 1, 100, 0, 0, "", "",
                                   "",
                                   0, 0, 0x0015, root));
}

ParaSetItem makeAParaSetItem(int macType, int showPriority, QString name, QString topImageName, int paraType)
{
    ParaSetItem item;
    item.clean();

    item.m_macType = macType;
    item.m_showPriority = showPriority;
    item.m_name = name;
    item.m_topImageName = topImageName;
    item.m_paraType = paraType;

    return item;
}

SensorItem makeASensorItem(int byte, int bit, QString name, int type)
{
    SensorItem item;
    item.clean();

    item.m_byte_offset = byte;
    item.m_bit_offset = bit;
    item.m_name = name;
    item.m_type = type;

    return item;
}

ErrorCodeStateItem makeAErrorStateItem(int code, QString name)
{
    ErrorCodeStateItem item;
    item.clean();

    item.m_code = code;
    item.m_name = name;

    return item;
}
